import Vue from 'vue'
import Router from 'vue-router'
import home from '@/views/home/routes'
import item from '@/views/topic/routes'
import login from '@/views/login/routes'
import archive from '@/views/archive/routes'
import project from '@/views/project/routes'
import about from '@/views/about/routes'
import message from '@/views/message/routes'
import search from '@/views/search/routes'

Vue.use(Router)

export const createRouter = () => new Router({
  mode: 'history',
  routes: [
    ...home,
    ...item,
    ...login,
    ...archive,
    ...project,
    ...about,
    ...message,
    ...search,
    {
      path: '/',
      component: () => import('@/components/layout/layout'),
      children: [
        {
          path: 'github',
          name: 'github',
          component: () => import('@/views/github')
        }
      ]
    },
    {
      path: '/repair',
      component: () => import('@/views/repair')
    },
    {
      path: '/control-freq',
      component: () => import('@/views/429')
    },
    {
      path: '/error',
      component: () => import('@/views/500')
    },
    {
      path: '/404',
      component: () => import('@/views/404')
    },
    {
      path: '*',
      component: () => import('@/views/404')
    }
  ],
  scrollBehavior (to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    }
    if (to.hash) {
      return {
        selector: to.hash
      }
    }
    return { x: 0, y: 0 }
  }
})
